package com.whut.cristiano.autographbook.Activity;

import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.List;

public class BaseActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = BaseActivity.class.getSimpleName();
    public static final String SMSSDK_APP_KEY = "1cb52e15a61ee";
    public static final String SMSSDK_APP_SECRET = "3e9481ec22d3ab84e7b58462149391e6";
    private ForceOffLineReceiver forceOffLineReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityManager.addActivity(this);
    }

    /**
     * 初始化广播接收器 注册
     */
    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.example.ykbboom.FORCE_OFFLINE");
        forceOffLineReceiver = new ForceOffLineReceiver();
        registerReceiver(forceOffLineReceiver, intentFilter);//广播接收器注册
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityManager.removeActivity(this);
    }


    public void showDialog(ProgressDialog progressDialog) {
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("正在进行...");
        progressDialog.show();
    }
    class ForceOffLineReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(final Context context, Intent intent) {

//            SharedPrefUtil.saveLoginState(false);
//            SharedPrefUtil.saveDriverState(false);
//            SharedPrefUtil.saveCheckDistance(3000);

            ActivityManager.finishAll();//销毁所有活动
            Intent intent1 = new Intent(context, LoginActivity.class);
            context.startActivity(intent1);


        }
    }
    @Override
    public void onClick(View v) {

    }

    public void initView() {

    }

}

